package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.entity.DishFlavor;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @projectName: HF62sky
 * @package: com.sky.controller.admin
 * @className: DishController
 * @author: SunGang
 * @description: TODO
 * @date: 2023/12/5 14:13
 * @version: 1.0
 */
@RestController
@RequestMapping("/admin/dish")
@RequiredArgsConstructor
public class DishController {
    private final DishService dishService;

    @PostMapping
    public Result add(@RequestBody DishDTO dishDTO) {
        dishService.add(dishDTO);
        return Result.success();
    }

    @GetMapping("/page")
    public Result<PageResult> page(DishPageQueryDTO dishPageQueryDTO) {
        PageResult page = dishService.page(dishPageQueryDTO);
        return Result.success(page);
    }

    @DeleteMapping
    public Result<?> delete(@RequestParam List<String> ids) {
        dishService.delete(ids);
        return Result.success();
    }

    @GetMapping("//{id}")
    public Result<DishVO> queryById(@PathVariable Long id) {
        DishVO dishVO = dishService.queryId(id);
        return Result.success(dishVO);
    }

    @PutMapping
    public Result modify(@RequestBody DishDTO dishDTO) {
        dishService.modify(dishDTO);
        return Result.success();
    }

    @GetMapping("/list")
    public Result<List<Dish>> list(Long categoryId) {
        List<Dish> dishes = dishService.list(categoryId);
        return Result.success(dishes);

    }
}
